//
//  GZMineController.swift
//  GZMarathon
//
//  Created by apple on 2021/10/27.
//

import UIKit

class GZMineController: EBBaseViewController {

    @IBOutlet weak var tab: UITableView!
    @IBOutlet weak var phoneLabel: UILabel!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var icon: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        tab.removeMoreLine()
        
    }
    
    func bindData() {
        nameLabel.text = GZCurrentUser.shared.currentUser?.account_name
        phoneLabel.text = GZCurrentUser.shared.currentUser?.account_phonenum
        guard let urlStr = GZCurrentUser.shared.currentUser?.account_avatar else{
            return
        }
        
        guard let url = URL(string: urlStr) else {
            return
        }
        icon.kf.setImage(with: url)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        bindData()
        self.navigationController?.navigationBar.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        self.navigationController?.navigationBar.isHidden = false
    }

    @IBAction func editClick(_ sender: UIButton) {
        
        let vc = UIStoryboard(name: "GM", bundle: nil).instantiateViewController(withIdentifier: "GZPersonInfoViewController") as! GZPersonInfoViewController
        self.navigationController?.pushViewController(vc, animated: true)
        
    }
    
    
    @IBAction func signOutClick(_ sender: UIButton) {
        
        let alertController = UIAlertController(title: "系统提示",
                        message: "您确定要退出登录吗？", preferredStyle: .alert)
        let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
        let okAction = UIAlertAction(title: "确定", style: .default, handler: {
            action in
            
            appdelegate().loginSence()
        })
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        self.present(alertController, animated: true, completion: nil)
        
        
        
        
    }
    
}




extension GZMineController:UITableViewDelegate,UITableViewDataSource{
    
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 54
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MineMainTableViewCell", for: indexPath) as! MineMainTableViewCell
        switch indexPath.row {
        case 0:
            cell.img.image = UIImage(named: "icon_wode_lianxiyunwei")
            cell.title.text = "联系运维"
        case 1:
            cell.img.image = UIImage(named: "icon_wode_changjianwenti")
            cell.title.text = "常见问题"
        default:
            cell.detail.isHidden = false
            cell.img.image = UIImage(named: "icon_wode_banben")
            cell.title.text = "版本信息"
            cell.detail.text = "1.0.0版本更新"
            
        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        switch indexPath.row {
        case 0:
            let vc = UIStoryboard(name: "GM", bundle: nil).instantiateViewController(withIdentifier: "UserViewController") as! UserViewController
            self.navigationController?.pushViewController(vc, animated: true)
            print("1")
        case 1:
            let vc = UIStoryboard(name: "GM", bundle: nil).instantiateViewController(withIdentifier: "ProblemViewController") as! ProblemViewController
            self.navigationController?.pushViewController(vc, animated: true)
            print("2")
        default:
            print("3")
        }
    }
    
}
